﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleNoteLib.Config;
using SimpleNoteLib.HttpRequests;

namespace SimpleNoteLib.ApiRequests
{
    internal class IndexRequest : HttpGetRequest
    {
        public int Length { get; set; }
        public string Token { get; set; }
        public string Email { get; set; }
        public string Mark { get; set; }
        public string Since { get; set; }

        public IndexRequest(string mark = null)
        {
            Length = 100;
            Token = Login.Token;
            Email = Login.Email;
            Mark = mark;
        }

        public IndexRequest(string token, string email, string mark = null)
            : this()
        {
            Token = token;
            Email = email;
            Mark = mark;
        }

        public override string SendAndGetResponse()
        {
            SetAddress();
            return base.SendAndGetResponse();
        }

        protected void SetAddress()
        {
            string address = string.Format("{0}index?length={1}", SimpleNoteApiConfig.ApiAddress, Length);
            if (string.IsNullOrWhiteSpace(Mark) == false)
            {
                address += string.Format("&mark={0}", Mark);
            }
            if (string.IsNullOrWhiteSpace(Since) == false)
            {
                address += string.Format("&since={0}", Since);
            }
            address += string.Format("&auth={0}&email={1}", Token, Email);
            //            string address = string.Format("{3}index?length={0}&auth={1}&email={2}",
            //                Length, Token, Email, SimpleNoteApiConfig.ApiAddress);
            Address = address;
        }
    }
}
